# Contributor: Jared Szechy <jared.szechy@gmail.com>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=librtlsdr
_realpkgname=rtl-sdr
pkgver=2.0.2
pkgrel=0
pkgdesc="Software defined radio receiver for Realtek RTL2832U"
url="https://osmocom.org/projects/sdr/wiki/rtl-sdr"
arch="all"
license="GPL-2.0-or-later"
options="!check" # no tests
depends_dev="libusb-dev"
makedepends="$depends_dev cmake samurai"
subpackages="$pkgname-dev rtl-sdr:tools $pkgname-doc"
source="$_realpkgname-$pkgver.tar.gz::https://github.com/osmocom/rtl-sdr/archive/refs/tags/v$pkgver.tar.gz
	correct_udev_rules_path.patch
	"
# use github mirror while it is impossible to download from gitea.osmocom.org
builddir="$srcdir/$_realpkgname-$pkgver"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX:PATH=/usr \
		-DDETACH_KERNEL_DRIVER=ON \
		-DINSTALL_UDEV_RULES=ON \
		-Wno-dev
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	mkdir -p $pkgdir/usr/share/man1/
	cp $builddir/debian/*1 $pkgdir/usr/share/man1/
}

tools() {
	pkgdesc="Software defined radio receiver for Realtek RTL2832U (tools)"
	amove usr/bin
}

doc() {
	pkgdesc="Software defined radio receiver for Realtek RTL2832U (doc)"
	amove usr/share/
}

sha512sums="
20a1630df7d4da5d263c5ffd4d83a7c2a6fc674e3838bf02b2b59c1da8d946dafc48790d410ab2fcbc0362c2ac70e5cdcae9391c5f04803bf2cdddafd6f58483  rtl-sdr-2.0.2.tar.gz
a191efe9ebb55696377ae4199178ba752719cbff5b3ecc8949c0e160a35480fb3bd3061588fe5f81c7a975d52c2071b82ad3b5454011d3f649de7912c9cb368c  correct_udev_rules_path.patch
"
